"""
API URL 配置
"""

from django.urls import path, include
from rest_framework.routers import DefaultRouter
from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
    TokenVerifyView,
)
from drf_spectacular.views import (
    SpectacularAPIView,
    SpectacularSwaggerView,
    SpectacularRedocView,
)

from .views import auth, product, category, carousel, upload, product_new, product_integrated, contact_message, customer, order

# 创建路由器
router = DefaultRouter()
router.register(r'products', product.ProductViewSet, basename='product')
router.register(r'products-new', product_new.ProductNewViewSet, basename='product-new')  # 新的产品管理
router.register(r'products-integrated', product_integrated.ProductIntegratedViewSet, basename='product-integrated')  # 集成的产品管理
router.register(r'categories', category.CategoryViewSet, basename='category')
router.register(r'carousels', carousel.CarouselViewSet, basename='carousel')
router.register(r'contact-messages', contact_message.ContactMessageViewSet, basename='contact-message')  # 客户留言管理
router.register(r'customers', customer.CustomerViewSet, basename='customer')  # 客户管理
router.register(r'orders', order.AdminOrderViewSet, basename='order')  # 订单管理

urlpatterns = [
    # ==================== 认证相关 ====================
    path('auth/login/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('auth/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
    path('auth/verify/', TokenVerifyView.as_view(), name='token_verify'),
    path('auth/me/', auth.CurrentUserView.as_view(), name='current_user'),
    path('auth/change-password/', auth.ChangePasswordView.as_view(), name='change_password'),

    # ==================== 文件上传 ====================
    path('upload/image/', upload.ImageUploadView.as_view(), name='upload_image'),
    path('upload/images/', upload.MultipleImageUploadView.as_view(), name='upload_images'),

    # ==================== RESTful API ====================
    path('', include(router.urls)),

    # ==================== API 文档 ====================
    path('schema/', SpectacularAPIView.as_view(), name='schema'),
    path('docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
    path('redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
]

